<?php
error_reporting(0);
session_start();
include_once '../comm/config.php';
include_once '../comm/checkpostandget.php';
include_once 'check.php';
include_once 'page.class.php';
include_once '../comm/wjt.php';

$keyword=$_GET["keyword"]; 
$act=$_GET['act'];
$page = !($_GET['page'])?'1':intval($_GET['page']);
$pagesize=10;
$page2=($page-1)*$pagesize;

if (!$act) {
	echo "缺少必要参数";
	exit;
}
else
{
	if($act=='taobao'){
		$sql="select * from ".$BIAOTOU."tradelist where outer_code='".$_SESSION["dduserid"]."' and outer_code<>''";
		$rs = mysql_query($sql);
		$total = mysql_num_rows($rs);	
		$sql="select * from ".$BIAOTOU."tradelist where outer_code='".$_SESSION["dduserid"]."' and outer_code<>'' order by pay_time desc limit $page2,$pagesize";
		$rs = mysql_query($sql);
	}
	
	if($act=='mall'){
		include_once 'getlink.php';
		$sql="select * from ".$BIAOTOU."mall_order where u_id='".$_SESSION["dduserid"]."' and u_id<>''";
		$rs = mysql_query($sql);
		$total = mysql_num_rows($rs);	
		$sql="select * from ".$BIAOTOU."mall_order where u_id='".$_SESSION["dduserid"]."' and u_id<>'' order by order_time desc limit $page2,$pagesize";
		$rs = mysql_query($sql);
	}
	
	if($act=='lost'){
		$sql="select * from ".$BIAOTOU."tradelist where  (trade_id like '%".$keyword."%' or item_title like '%".$keyword."%') and (outer_code='' or outer_code is NULL)";
		$rs = mysql_query($sql);
		$total = mysql_num_rows($rs);	
		$sql="select * from ".$BIAOTOU."tradelist where (trade_id like '%".$keyword."%' or item_title like '%".$keyword."%') and  (outer_code='' or outer_code is NULL) order by pay_time desc limit $page2,$pagesize";
		$rs = mysql_query($sql);
	}
	
	if($act=='malllost'){
		$sql="select * from ".$BIAOTOU."mall_order where  order_code like '%".$keyword."%' and (u_id='' or u_id is NULL)";
		$rs = mysql_query($sql);
		$total = mysql_num_rows($rs);	
		$sql="select * from ".$BIAOTOU."mall_order where order_code like '%".$keyword."%' and  (u_id='' or u_id is NULL) order by order_time desc limit $page2,$pagesize";
		$rs = mysql_query($sql);
	}
	if($act=='checked'){
		$sql="select * from ".$BIAOTOU."tradelist where outer_code='".$_SESSION["dduserid"]."' and outer_code<>'' and checked=1";
		$rs = mysql_query($sql);
		$total = mysql_num_rows($rs);	
		$sql="select * from ".$BIAOTOU."tradelist where outer_code='".$_SESSION["dduserid"]."' and outer_code<>'' and checked=1 order by pay_time desc limit $page2,$pagesize";
		$rs = mysql_query($sql);
	}
}

$tag="center";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<title>我的订单管理 - 用户中心</title>
<link href="../css/usercss.css" rel="stylesheet" type="text/css">
<link href="../template/<?=MOBAN?>/css/common.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="../js/jquery.js"></script>
<script>
function checkTradelist(){
    var keyword=document.getElementById('keyword').value;
	if(keyword=='输入订单号' || keyword==''){
	    alert('订单号不能为空');
		return false;
	}
}
</script>
</head>

<body id="tradelist">
<?php
include("../template/".MOBAN."/header.tpl.php");
?>
<?php
include("../template/".MOBAN."/nav.tpl.php");
?>
<div id="main">
<?php
include("left.php");
?>
<div class="contain">
  <h2 class="left_nav2">我的订单管理 <span><form action="tradelist.php" onsubmit="return checkTradelist()"><input type="text" id="keyword" name="keyword" value="输入订单号" style="color:#999;font-size:12px;" onclick="this.value=''" /><select name="act" style="margin-left:10px;font-size:12px;"><option value="lost">淘宝订单</option><option value="malllost">商城订单</option></select><input class="smtgray" type="submit" value="查找遗漏订单" style="margin-left:10px; font-size:12px;" /></form></span></h2>
    <div class="order">
      <div class="title">
          <ul>
            <li><a style="MARGIN-LEFT: 10px" <?php if($act=='taobao') echo "class=\"current\"";?>
  href="tradelist.php?act=taobao">我的淘宝订单</a></li>
  			<li><a style="MARGIN-LEFT: 10px" <?php if($act=='mall') echo "class=\"current\"";?>
  href="tradelist.php?act=mall">我的商城订单</a></li>
  			<li><a style="MARGIN-LEFT: 10px" <?php if($act=='lost') echo "class=\"current\"";?>
  href="tradelist.php?act=lost">找回订单(淘宝)</a></li>
  			<li><a style="MARGIN-LEFT: 10px" <?php if($act=='malllost') echo "class=\"current\"";?>
  href="tradelist.php?act=malllost">找回订单(商城)</a></li>
  <li><a style="MARGIN-LEFT: 10px" <?php if($act=='checked') echo "class=\"current\"";?>
  href="tradelist.php?act=checked">待审核订单(淘宝)</a></li>
          </ul>
      </div>    
	  <div class="content">
      <ul style="width:710px">
	  		<?php if($act=='taobao'){?>
				<li class="order_title">
				<div class="item" style="width:120px">&nbsp;&nbsp;订单号</div>
				<div class="item" style="width:370px;">宝贝名称</div>
				<div class="item" style="width:60px;text-align:center">单价</div>
				<div class="item" style="width:60px;text-align:center">返现</div>
				<div class="item" style="width:100px;text-align:center">成交时间</div>
				</li>
			<?php
			while ($row = mysql_fetch_array($rs))
			{
				echo "<li><div class=\"item\" style=\"width:120px\">&nbsp;&nbsp;".$row["trade_id"]."</div>";
				echo "<div class=\"item\" style=\"width:370px\">".$row["item_title"]."</div>";
				echo "<div class=\"item\" style=\"width:60px;text-align:center\">".$row["pay_price"]."</div>";
				echo "<div class=\"item\" style=\"width:60px;text-align:center\">".round($row["fxje"],2)."</div>";						
				echo "<div class=\"item\" style=\"width:100px;text-align:center\">".$row["pay_time"]."</div>";
				echo "</li>";
			}
			?></ul>
			<?php }?>
            
            <?php if($act=='checked'){?>
				<li class="order_title">
				<div class="item" style="width:120px">&nbsp;&nbsp;订单号</div>
				<div class="item" style="width:370px;">宝贝名称</div>
				<div class="item" style="width:60px;text-align:center">单价</div>
				<div class="item" style="width:60px;text-align:center">返现</div>
				<div class="item" style="width:100px;text-align:center">成交时间</div>
				</li>
			<?php
			while ($row = mysql_fetch_array($rs))
			{
				echo "<li><div class=\"item\" style=\"width:120px\">&nbsp;&nbsp;".$row["trade_id"]."</div>";
				echo "<div class=\"item\" style=\"width:370px\">".$row["item_title"]."</div>";
				echo "<div class=\"item\" style=\"width:60px;text-align:center\">".$row["pay_price"]."</div>";
				echo "<div class=\"item\" style=\"width:60px;text-align:center\">".round($row["fxje"],2)."</div>";						
				echo "<div class=\"item\" style=\"width:100px;text-align:center\">".$row["pay_time"]."</div>";
				echo "</li>";
			}
			?></ul>
			<?php }?>
            
            	
		  		<?php if($act=='mall'){?>
				<li class="order_title">
				<div class="item" style="width:160px;text-align:center">&nbsp;&nbsp;订货号</div>
				<div class="item" style="width:70px;text-align:center">下单商城</div>
				<div class="item" style="width:100px;text-align:center">成交数量</div>				
				<div class="item" style="width:90px;text-align:center">单价</div>				
				<div class="item" style="width:90px;text-align:center">返现</div>
				<div class="item" style="width:100px;text-align:center">成交时间</div>
				<div class="item" style="width:100px;text-align:center">交易状态</div>
				</li>
			<?php
			while ($row = mysql_fetch_array($rs))
			{echo 111;
				echo "<li><div class=\"item\" style=\"width:160px;text-align:center\">&nbsp;&nbsp;".$row["order_code"]."</div>";
				echo "<div class=\"item\" style=\"width:70px;text-align:center\">".$row["merchant_id"]."</div>";
				echo "<div class=\"item\" style=\"width:100px;text-align:center\">".$row["item_count"]."</div>";
				echo "<div class=\"item\" style=\"width:90px;text-align:center\">".$row["item_price"]."</div>";
				echo "<div class=\"item\" style=\"width:90px;text-align:center\">".round($row["fxje"],2)."</div>";						
				echo "<div class=\"item\" style=\"width:100px;text-align:center\">".$row["order_time"]."</div>";
				echo "<div class=\"item\" style=\"width:100px;text-align:center\">".$row["stat_desc"]."</div>";
				echo "</li>";
			}
			?></ul>
			<?php }?>	
			
	  	  	<?php if($act=='lost'){?>
				<li class="order_title">
				<div class="item" style="width:120px">&nbsp;&nbsp;订单号</div>
				<div class="item" style="width:270px">宝贝名称</div>
				<div class="item" style="width:60px; text-align:center">单价</div>
				<div class="item" style="width:60px; text-align:center">返现</div>
				<div class="item" style="width:100px; text-align:center">成交时间</div>
				<div class="item" style="width:100px; text-align:center">找回订单</div>
				</li>
			<?php
			while ($row = mysql_fetch_array($rs))
			{
				$th="";
				for($len=strlen($row["trade_id"])-3;$len>0;$len=$len-1)
				{
					$th=$th."*";
				}
				echo "<li><div class=\"order_detail\"><div class=\"item\" style=\"width:120px\">&nbsp;&nbsp;".substr($row["trade_id"],0,1)."".$th."".substr($row["trade_id"],strlen($row["trade_id"])-1,1)."</div>";
				echo "<div class=\"item\" style=\"width:270px\">".$row["item_title"]."</div>";
				echo "<div class=\"item\" style=\"width:60px;text-align:center\">".$row["pay_price"]."</div>";
				echo "<div class=\"item\" style=\"width:60px;text-align:center\">".ck_fxje($row["commission"],$_SESSION["dduserlevel"])."</div>";						
				echo "<div class=\"item\" style=\"width:100px;text-align:center\">".$row["pay_time"]."</div>";
				echo "<div class=\"item\" style=\"width:100px;text-align:center\"><a href=\"queren.php?id=".$row["Id"]."\"><img src=../images/queren.gif width=86 height=20 alt=\"我要确认这份订单\" border=0 /></a></div></li>";
			}
			?></ul>
	<?php }?>	
	<?php if($act=='malllost'){?>
				<li class="order_title">
				<div class="item" style="width:110px">&nbsp;&nbsp;订单号</div>
				<div class="item" style="width:120px">下单商城</div>
				<div class="item" style="width:100px;text-align:center">成交数量</div>				
				<div class="item" style="width:90px;text-align:center">单价</div>				
				<div class="item" style="width:90px;text-align:center">返现</div>
				<div class="item" style="width:100px;text-align:center">成交时间</div>
				<div class="item" style="width:100px;text-align:center">找回订单</div>
				</li>
			<?php
			while ($row = mysql_fetch_array($rs))
			{
				$th="";
				for($len=strlen($row["order_code"])-3;$len>0;$len=$len-1)
				{
					$th=$th."*";
				}
				echo "<li><div class=\"order_detail\"><div class=\"item\" style=\"width:110px\">&nbsp;&nbsp;".substr($row["order_code"],0,1)."".$th."".substr($row["order_code"],strlen($row["order_code"])-1,1)."</div>";
				echo "<div class=\"item\" style=\"width:120px\">".$row["merchant_id"]."</div>";
				echo "<div class=\"item\" style=\"width:100px;text-align:center\">".$row["item_count"]."</div>";
				echo "<div class=\"item\" style=\"width:90px;text-align:center\">".$row["item_price"]."</div>";
				echo "<div class=\"item\" style=\"width:90px;text-align:center\">".mall_ck_fxje($row["commission"],$_SESSION["dduserlevel"])."</div>";						
				echo "<div class=\"item\" style=\"width:100px;text-align:center\">".$row["order_time"]."</div>";
				echo "<div class=\"item\" style=\"width:100px;text-align:center\"><a href=\"queren_mall.php?id=".$row["id"]."\"><img src=../images/queren.gif width=86 height=20 alt=\"我要确认这份订单\" border=0 /></a></div></li>";
			}
			?></ul>
			<?php }?>
	</div>
	</div>
</div>
	<div class="megas512" style="clear:both"><?php pageft($total,$pagesize,1,1,0,10,"tradelist.php?act=".$act."");	echo $pagenav;?></div>
</div>
<?php
include("../template/".MOBAN."/footer.tpl.php");
mysql_close();
?>
</body>
</html>